package com.qingcheng.controller;

import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.system.Role;
import com.qingcheng.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/findAll")
    public Result findAll(){
        List<Role> all = roleService.findAll();
        return  new Result(200,"查询成功",all);
    }

    @GetMapping("/findPage")
    public PageResult<Role> findPage(int page, int size){
        return roleService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Role> findList(@RequestBody Map<String,Object> searchMap){
        return roleService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Role> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  roleService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Role findById(Integer id){
        return roleService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Role role){
        roleService.add(role);
        return new Result(200,"新增成功",1);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        roleService.delete(id);
        return new Result();
    }

    @GetMapping("queryByRole")
    public  Result queyrByRole(Integer page,Integer size){
        PageResult<Map> mapPageResult = this.roleService.queryByRole(page, size);
        return  new Result(200,"查询成功",mapPageResult);
    }

    @PostMapping("addRules")
    public  Result addRules(Integer roleId,@RequestBody String ids){
         this.roleService.addRules(roleId,ids);
          return  new Result(200,"新增或删除成功",1);
    }
}
